<template>
  <el-dialog
    title="编辑会员"
    :visible.sync="isShow"
    center
    :before-close="cancel"
  >
    <el-form :model="form" :rules="rules" ref="form">
      <el-form-item prop="phone" label="手机号" :label-width="formLabelWidth">
        <el-input v-model="form.phone" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item prop="nickname" label="昵称" :label-width="formLabelWidth">
        <el-input v-model="form.nickname" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="密码" :label-width="formLabelWidth">
        <el-input
          type="password"
          placeholder="留空则不做修改"
          disabled
          v-model="form.password"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item label="状态" :label-width="formLabelWidth">
        <el-switch
          v-model="form.status"
          active-color="#409EFF"
          inactive-color="#DCDFE6"
          :active-value="1"
          :inactive-value="2"
        >
        </el-switch>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="comfirm">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { memberEdit, memberInfo } from "@/request/api";
import { mapActions } from "vuex";
export default {
  props: ["isShow"],
  data() {
    return {
      form: {
        uid: "", // 会员编号
        nickname: "", // 昵称
        phone: "", // 手机号
        password: "", // 密码
        status: 1, // 状态1正常2禁用
      },
      formLabelWidth: "120px",
      rules: {
        nickname: [
          { required: true, message: "请输入昵称", trigger: "blur" },
          { min: 2, max: 6, message: "长度在 2 到 6 个字符", trigger: "blur" },
        ],
      },
    };
  },
  mounted() {
    this.getMember();
  },
  methods: {
    ...mapActions({
      getMember: "member/changeMemberAction",
    }),
    lookup(uid) {
      memberInfo({
        uid,
      }).then((res) => {
        console.log(res, "获取一条数据");
        if (res.code == 200) {
          this.form = res.list;
          this.form.uid = uid;
          this.form.password = "";
        }
      });
    },
    // reset() {
    //   this.form = {
    //     uid: "", // 会员编号
    //     nickname: "", // 昵称
    //     phone: "", // 手机号
    //     password: "", // 密码
    //     status: 1, // 状态1正常2禁用
    //   };
    // this.$refs.form.resetFields();
    // },
    cancel() {
      this.$emit("cancel", false);
      // this.reset();
    },
    comfirm() {
      memberEdit(this.form).then((res) => {
        console.log(res, "会员编辑");
        if (res.code == 200) {
          this.$message.success(res.msg);
          this.cancel();
          this.getMember();
        } else {
          this.$message.error(res.msg);
        }
      });
    },
  },
};
</script>

<style lang="less"scoped>
</style>
